#ifndef _H_WOP_INT_PROXY_H_
#define _H_WOP_INT_PROXY_H_

#include "all_entries.h"
extern HINSTANCE _hInst ;  // this instance is defined in DIVA_MAIN
extern HWND _hWnd ;        // this instance is defined in DIVA_Application

BOOL CALLBACK CompPtvProc(HWND,UINT,WPARAM,LPARAM);
extern WOP_Entry* currentEntry;
extern xMappingTree* mTree;
/**
	hyt - 09/09/27 新增WOP_Int_Proxy
	      09/10/05 新增setUpdated,setChanged,setScope , 修正未更新的bug
		           setVM 也由WOP_proxy完成xmappingTree, 需跟老闆check
				   由於更新須由Proxy這邊來更新 , 所以KeyFrameObject在判斷WOP_Entry值需不需要更新
				   必須取得WOP_Entry的實體 , 並非 Proxy , 所以新增getEntry() method
**/

class WOP_Int_Proxy : public WOP_Entry{
	private:
		int _val;
		double _vald;
		float _valf;
		WOP_Int_Entry* _en;
		WOP_Int_Proxy(){}
	public:
		WOP_Int_Proxy(WOP_Int_Entry* en){
			this->_en = en;
			init(*(en->getNamePtr()),en->getParent());
		}
		int* getIntValAddr() {return &_val;}
		double* getDoubleValAddr() { return &_vald ; }
		float* getFloatValAddr() {return &_valf;}
		WOP_Int_Entry* getEntry(){return this->_en;}
		string getTypeStr() { return std::string("int"); }		
		
		virtual void setVal(string s){
			this->_en->setVal(s);
			this->_value = s;
		}
		virtual void setAddr(string s){
			this->_en->setAddr(s);
			this->_addr = s;
		}
		virtual void setVarType(string s){
			this->_en->setVarType(s);
			this->_vartype = s;
		}
		/* added by ypc */
		virtual void setName(string name) {	
			this->_en->setName(name);
			this->_name = name ;
		}
		virtual void setFrom(WOP_Entry *s){		
			this->_en->setFrom(s);
			this->_from = s;
		}
		virtual void setDescentFrom(WOP_Entry * from){
			this->_en->setDescentFrom(from);
			if (from != NULL) {
				if (from->isTop()) 
					this->_descentfrom = from ;
				else  
					this->_descentfrom = from->getDescentFrom();
			}
		}
		virtual void setTop(bool t){		
			this->_en->setTop(t);
			_top = t;
		}
		virtual void setUpdated(bool t){		
			this->_en->setUpdated(t);
			this->_updated = t;
		}
		virtual void setChanged(bool t){		
			this->_en->setChanged(t);
			this->_changed = t;
		}
		virtual void setScope(bool t){		
			this->_en->setScope(t);
			this->_inscope = t;
		}

		virtual bool update(){
			bool real_en_update;
			real_en_update = _en->update();
			if(real_en_update){
				this->_val = *(_en->getIntValAddr());
				this->_vald = *(_en->getDoubleValAddr());
				this->_valf = *(_en->getFloatValAddr());
				this->_value = _en->getVal();
				this->_changed = _en->update();
			}
			this->_changed = real_en_update;
			return this->_changed;
		}
		void updateProxyValue(string s){
			int value ;
			_value = s ;
			if(from_string<int>(value, std::string(_value), std::boolalpha)) {
				_val = value ;
				_vald = (double)_val;
				_valf = (float)_val;
				this->_changed = true;
			} 
			else{ 
				assert(false);
			}			
		}
		virtual void updateRealValue(string s) {
			int value ;
			_value = s ;
			if(from_string<int>(value, std::string(_value), std::boolalpha)) {
				_val = value ;
				_vald = (double)_val;
				_valf = (float)_val;
			} else assert(false);
		}	
};
#endif